FROM ubuntu-java:14.04

ENV TOMCAT_MAJOR_VERSION=7 \
    TOMCAT_MINOR_VERSION=7.0.72 \
    CATALINA_HOME=/tomcat \
    TOMCAT_HOME=/tomcat

RUN echo 'export TOMCAT_HOME=/tomcat' >>/etc/profile && \
    echo 'export CATALINA_HOME=/tomcat' >>/etc/profile

RUN apt-get update && \
    apt-get -y install pwgen && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* && \
    pip install requests 

# INSTALL TOMCAT
ADD https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v${TOMCAT_MINOR_VERSION}/bin/apache-tomcat-${TOMCAT_MINOR_VERSION}.tar.gz /
RUN tar xf /apache-tomcat-*.tar.gz && \
    rm /apache-tomcat-*.tar.gz && \
    mv /apache-tomcat* /tomcat

ADD create_tomcat_admin_user.sh /create_tomcat_admin_user.sh
ADD run.sh /run.sh

EXPOSE 8080
CMD ["/run.sh"]

RUN  sed -i '1a JAVA_OPTS="$JAVA_OPTS -server -Xms2048m -Xmx2048m -XX:MaxNewSize=256m  -XX:PermSize=128M -XX:MaxPermSize=512m -Xss512k"' /tomcat/bin/catalina.sh && \
sed -i '/<Connector port="8080"/a   maxThreads="800" acceptCount="1000" maxPostSize="0" URIEncoding="UTF-8"' /tomcat/conf/server.xml && \
sed -i 's/port="8009"/port="8009"  maxThreads="800" acceptCount="1000" maxPostSize="0" URIEncoding="UTF-8"/' /tomcat/conf/server.xml && \
sed -i 'N;/\n.*tomcatThreadPool/!P;D' /tomcat/conf/server.xml && \
sed -i '/minSpareThreads/{n;/-->/d}' /tomcat/conf/server.xml && \
sed -i '/redirectPort/{n;/-->/d}' /tomcat/conf/server.xml && \
sed -i '/<Connector port="8080"/,/\/>/d' /tomcat/conf/server.xml && \
sed -i '/<Executor name="tomcatThreadPool"/,/\/>/{s/150/1000/}' /tomcat/conf/server.xml && \
sed -i '/<Executor name="tomcatThreadPool"/,/\/>/{s/4/300/}' /tomcat/conf/server.xml && \
####<Connector executor="tomcatThreadPool" port="80" protocol="HTTP/1.1"  connectionTimeout="20000"
#### enableLookups="false" redirectPort="8443" URIEncoding="UTF-8" acceptCount="1000" />
sed -i '/Connector executor="tomcatThreadPool"/a enableLookups="false" URIEncoding="UTF-8" acceptCount="1000"' /tomcat/conf/server.xml

#RUN  sed -i '/<tomcat-users>/,/<\/tomcat-users>/d' /tomcat/conf/tomcat-users.xml

RUN cat /tomcat/conf/context.xml

RUN sed -i '/<!–/,/–>/d' /tomcat/conf/server.xml
RUN sed -i '/<!–/,/–>/d' /tomcat/conf/tomcat-users.xml

COPY showlog.sh /usr/local/bin/showlog.sh

